<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备序列号，全局唯一" prop="deviceid">
        <el-input
          v-model="queryParams.deviceid"
          placeholder="请输入设备序列号，全局唯一"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="gps设备上报的时间" prop="devicetime">
        <el-input
          v-model="queryParams.devicetime"
          placeholder="请输入gps设备上报的时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到达服务器时间" prop="arrivedtime">
        <el-input
          v-model="queryParams.arrivedtime"
          placeholder="请输入到达服务器时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="综合计算后位置更新时间" prop="updatetime">
        <el-input
          v-model="queryParams.updatetime"
          placeholder="请输入综合计算后位置更新时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最后位置定位时间" prop="validpoistiontime">
        <el-input
          v-model="queryParams.validpoistiontime"
          placeholder="请输入最后位置定位时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计算出来的纬度" prop="callat">
        <el-input
          v-model="queryParams.callat"
          placeholder="请输入计算出来的纬度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计算出来的经度" prop="callon">
        <el-input
          v-model="queryParams.callon"
          placeholder="请输入计算出来的经度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="高度(米)" prop="altitude">
        <el-input
          v-model="queryParams.altitude"
          placeholder="请输入高度(米)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="定位精度米" prop="radius">
        <el-input
          v-model="queryParams.radius"
          placeholder="请输入定位精度米"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="速度 (米)" prop="speed">
        <el-input
          v-model="queryParams.speed"
          placeholder="请输入速度 (米)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="方向 (0-360)" prop="course">
        <el-input
          v-model="queryParams.course"
          placeholder="请输入方向 (0-360)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总里程米" prop="totaldistance">
        <el-input
          v-model="queryParams.totaldistance"
          placeholder="请输入总里程米"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总油量" prop="totaloil">
        <el-input
          v-model="queryParams.totaloil"
          placeholder="请输入总油量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总非行驶油耗" prop="totalnotrunningad">
        <el-input
          v-model="queryParams.totalnotrunningad"
          placeholder="请输入总非行驶油耗"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分开统计的时候第1个油箱" prop="masteroil">
        <el-input
          v-model="queryParams.masteroil"
          placeholder="请输入分开统计的时候第1个油箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分开统计的时候第2个油箱" prop="auxoil">
        <el-input
          v-model="queryParams.auxoil"
          placeholder="请输入分开统计的时候第2个油箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分开统计的时候第3个油箱" prop="thirdoil">
        <el-input
          v-model="queryParams.thirdoil"
          placeholder="请输入分开统计的时候第3个油箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分开统计的时候第4个油箱" prop="fourthoil">
        <el-input
          v-model="queryParams.fourthoil"
          placeholder="请输入分开统计的时候第4个油箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油量模拟量1" prop="srcad0">
        <el-input
          v-model="queryParams.srcad0"
          placeholder="请输入油量模拟量1"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油量模拟量2" prop="srcad1">
        <el-input
          v-model="queryParams.srcad1"
          placeholder="请输入油量模拟量2"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油量模拟量3" prop="srcad2">
        <el-input
          v-model="queryParams.srcad2"
          placeholder="请输入油量模拟量3"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油量模拟量4" prop="srcad3">
        <el-input
          v-model="queryParams.srcad3"
          placeholder="请输入油量模拟量4"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否启用 0未启用，1启用" prop="isAvailable">
        <el-input
          v-model="queryParams.isAvailable"
          placeholder="请输入是否启用 0未启用，1启用"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="租户id" prop="tenantId">
        <el-input
          v-model="queryParams.tenantId"
          placeholder="请输入租户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['gwebmgr:records:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['gwebmgr:records:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['gwebmgr:records:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['gwebmgr:records:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="记录ID" align="center" prop="recordsid" />
      <el-table-column label="设备序列号，全局唯一" align="center" prop="deviceid" />
      <el-table-column label="gps设备上报的时间" align="center" prop="devicetime" />
      <el-table-column label="到达服务器时间" align="center" prop="arrivedtime" />
      <el-table-column label="综合计算后位置更新时间" align="center" prop="updatetime" />
      <el-table-column label="最后位置定位时间" align="center" prop="validpoistiontime" />
      <el-table-column label="计算出来的纬度" align="center" prop="callat" />
      <el-table-column label="计算出来的经度" align="center" prop="callon" />
      <el-table-column label="高度(米)" align="center" prop="altitude" />
      <el-table-column label="定位精度米" align="center" prop="radius" />
      <el-table-column label="速度 (米)" align="center" prop="speed" />
      <el-table-column label="方向 (0-360)" align="center" prop="course" />
      <el-table-column label="总里程米" align="center" prop="totaldistance" />
      <el-table-column label="总油量" align="center" prop="totaloil" />
      <el-table-column label="总非行驶油耗" align="center" prop="totalnotrunningad" />
      <el-table-column label="分开统计的时候第1个油箱" align="center" prop="masteroil" />
      <el-table-column label="分开统计的时候第2个油箱" align="center" prop="auxoil" />
      <el-table-column label="分开统计的时候第3个油箱" align="center" prop="thirdoil" />
      <el-table-column label="分开统计的时候第4个油箱" align="center" prop="fourthoil" />
      <el-table-column label="油量模拟量1" align="center" prop="srcad0" />
      <el-table-column label="油量模拟量2" align="center" prop="srcad1" />
      <el-table-column label="油量模拟量3" align="center" prop="srcad2" />
      <el-table-column label="油量模拟量4" align="center" prop="srcad3" />
      <el-table-column label="是否启用 0未启用，1启用" align="center" prop="isAvailable" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="租户id" align="center" prop="tenantId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['gwebmgr:records:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['gwebmgr:records:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改最后位置列51GPS对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="设备序列号，全局唯一" prop="deviceid">
          <el-input v-model="form.deviceid" placeholder="请输入设备序列号，全局唯一" />
        </el-form-item>
        <el-form-item label="gps设备上报的时间" prop="devicetime">
          <el-input v-model="form.devicetime" placeholder="请输入gps设备上报的时间" />
        </el-form-item>
        <el-form-item label="到达服务器时间" prop="arrivedtime">
          <el-input v-model="form.arrivedtime" placeholder="请输入到达服务器时间" />
        </el-form-item>
        <el-form-item label="最后位置定位时间" prop="validpoistiontime">
          <el-input v-model="form.validpoistiontime" placeholder="请输入最后位置定位时间" />
        </el-form-item>
        <el-form-item label="计算出来的纬度" prop="callat">
          <el-input v-model="form.callat" placeholder="请输入计算出来的纬度" />
        </el-form-item>
        <el-form-item label="计算出来的经度" prop="callon">
          <el-input v-model="form.callon" placeholder="请输入计算出来的经度" />
        </el-form-item>
        <el-form-item label="高度(米)" prop="altitude">
          <el-input v-model="form.altitude" placeholder="请输入高度(米)" />
        </el-form-item>
        <el-form-item label="定位精度米" prop="radius">
          <el-input v-model="form.radius" placeholder="请输入定位精度米" />
        </el-form-item>
        <el-form-item label="速度 (米)" prop="speed">
          <el-input v-model="form.speed" placeholder="请输入速度 (米)" />
        </el-form-item>
        <el-form-item label="方向 (0-360)" prop="course">
          <el-input v-model="form.course" placeholder="请输入方向 (0-360)" />
        </el-form-item>
        <el-form-item label="总里程米" prop="totaldistance">
          <el-input v-model="form.totaldistance" placeholder="请输入总里程米" />
        </el-form-item>
        <el-form-item label="总油量" prop="totaloil">
          <el-input v-model="form.totaloil" placeholder="请输入总油量" />
        </el-form-item>
        <el-form-item label="总非行驶油耗" prop="totalnotrunningad">
          <el-input v-model="form.totalnotrunningad" placeholder="请输入总非行驶油耗" />
        </el-form-item>
        <el-form-item label="分开统计的时候第1个油箱" prop="masteroil">
          <el-input v-model="form.masteroil" placeholder="请输入分开统计的时候第1个油箱" />
        </el-form-item>
        <el-form-item label="分开统计的时候第2个油箱" prop="auxoil">
          <el-input v-model="form.auxoil" placeholder="请输入分开统计的时候第2个油箱" />
        </el-form-item>
        <el-form-item label="分开统计的时候第3个油箱" prop="thirdoil">
          <el-input v-model="form.thirdoil" placeholder="请输入分开统计的时候第3个油箱" />
        </el-form-item>
        <el-form-item label="分开统计的时候第4个油箱" prop="fourthoil">
          <el-input v-model="form.fourthoil" placeholder="请输入分开统计的时候第4个油箱" />
        </el-form-item>
        <el-form-item label="油量模拟量1" prop="srcad0">
          <el-input v-model="form.srcad0" placeholder="请输入油量模拟量1" />
        </el-form-item>
        <el-form-item label="油量模拟量2" prop="srcad1">
          <el-input v-model="form.srcad1" placeholder="请输入油量模拟量2" />
        </el-form-item>
        <el-form-item label="油量模拟量3" prop="srcad2">
          <el-input v-model="form.srcad2" placeholder="请输入油量模拟量3" />
        </el-form-item>
        <el-form-item label="油量模拟量4" prop="srcad3">
          <el-input v-model="form.srcad3" placeholder="请输入油量模拟量4" />
        </el-form-item>
        <el-form-item label="删除状态" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除状态" />
        </el-form-item>
        <el-form-item label="是否启用 0未启用，1启用" prop="isAvailable">
          <el-input v-model="form.isAvailable" placeholder="请输入是否启用 0未启用，1启用" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="租户id" prop="tenantId">
          <el-input v-model="form.tenantId" placeholder="请输入租户id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecords, getRecords, delRecords, addRecords, updateRecords, exportRecords } from "@/api/gwebmgr/records";

export default {
  name: "Records",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 最后位置列51GPS表格数据
      recordsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceid: null,
        devicetime: null,
        arrivedtime: null,
        updatetime: null,
        validpoistiontime: null,
        callat: null,
        callon: null,
        altitude: null,
        radius: null,
        speed: null,
        course: null,
        totaldistance: null,
        totaloil: null,
        totalnotrunningad: null,
        masteroil: null,
        auxoil: null,
        thirdoil: null,
        fourthoil: null,
        srcad0: null,
        srcad1: null,
        srcad2: null,
        srcad3: null,
        isAvailable: null,
        tenantId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询最后位置列51GPS列表 */
    getList() {
      this.loading = true;
      listRecords(this.queryParams).then(response => {
        this.recordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recordsid: null,
        deviceid: null,
        devicetime: null,
        arrivedtime: null,
        updatetime: null,
        validpoistiontime: null,
        callat: null,
        callon: null,
        altitude: null,
        radius: null,
        speed: null,
        course: null,
        totaldistance: null,
        totaloil: null,
        totalnotrunningad: null,
        masteroil: null,
        auxoil: null,
        thirdoil: null,
        fourthoil: null,
        srcad0: null,
        srcad1: null,
        srcad2: null,
        srcad3: null,
        delFlag: null,
        isAvailable: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        tenantId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recordsid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加最后位置列51GPS";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const recordsid = row.recordsid || this.ids
      getRecords(recordsid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改最后位置列51GPS";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.recordsid != null) {
            updateRecords(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecords(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const recordsids = row.recordsid || this.ids;
      this.$modal.confirm('是否确认删除最后位置列51GPS编号为"' + recordsids + '"的数据项？').then(function() {
        return delRecords(recordsids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有最后位置列51GPS数据项？').then(() => {
        this.exportLoading = true;
        return exportRecords(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
